package com.example.controllers;

import com.alibaba.fastjson.JSON;
import com.example.models.Book;
import com.example.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("ex.TestController")
@RequestMapping("/ex/tc")
public class TestController {
    @Autowired
    private BookService bookService;

    @RequestMapping("t")
    public String test() {
        String id = "KT3tp85Nqkx7OKEk8gZUXeWZZpmtmbgu";
        Book book = bookService.getById(id);
        return JSON.toJSONString(book);
    }

    @RequestMapping("qn")
    public String queryByName() {
        Iterable<Book> books = bookService.queryByName("itclj_rest_test_hHz6Fl6Ceo");
        return JSON.toJSONString(books);
    }

    @RequestMapping("qa")
    public String queryByAuthor() {
        Iterable<Book> books = bookService.queryByAuthor("作者");
        return JSON.toJSONString(books);
    }

}
